import requests
import random
import redis



def get_request_url():
    client = redis.Redis(host='localhost', port=6379, db=0)
    url= client.lpop("request_urls")
    client.close()
    return url.decode('utf8')

def callback_urls(url):
    client = redis.Redis(host='localhost', port=6379, db=0)
    client.lpush("request_urls", url)
    client.close()

urls = set()
for i in range(0, random.randint(1, 5)):
    url = get_request_url()
    urls.add(url)
print(urls)


for url in urls:
    try:
        response = requests.get(url, timeout=1)
        print(response.json())
    except Exception as e:
        print(e, f"{url}重新存储")
        callback_urls(url)